<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 设备监控
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.organNm" placeholder="医院名称" class="handle-input mr10" @keyup.enter.native="handleSearch"></el-input>
                <el-input v-model="query.bkOrganId" placeholder="系统编号" class="handle-input mr10" @keyup.enter.native="handleSearch"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                <el-button type="el-button" icon="el-icon-delete" @click="handleReset">重置</el-button>
            </div>
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <!--<el-table-column type="selection" width="55" align="center"></el-table-column>-->
                <el-table-column prop="systemId" label="系统ID" width="200" align="center"></el-table-column>
                <el-table-column v-if="show" prop="systemType" label="设备类别" width="200" align="center"></el-table-column>
                <el-table-column v-if="show" prop="organId" label="医院编号" align="center"></el-table-column>
                <el-table-column prop="organNm" label="医院名称" align="center"></el-table-column>
                <el-table-column prop="bkOrganId" label="系统编号" align="center"></el-table-column>
                <el-table-column prop="bkOrganNm" label="系统名称" align="center"></el-table-column>
                <el-table-column v-if="show" prop="istTm" label="插入时间"></el-table-column>
                <el-table-column v-if="show" prop="systemStatus" label="设备状态" align="center"></el-table-column>
                <el-table-column v-if="show" prop="systemStatusText" label="设备状态" align="center"></el-table-column>
                <el-table-column prop="tag" label="设备状态" width="200" filter-placement="bottom-end" align="center">
                    <template slot-scope="scope">
                        <el-tag :type="scope.row.systemStatus === '00' ? 'primary' : 'success'" disable-transitions>{{scope.row.systemStatusText}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="250" align="center">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.systemStatus=='00'"
                                   type="text"
                                   icon="el-icon-view"
                                   @click="handleView(scope.$index, scope.row)"
                        >查看</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="total, prev, pager, next"
                        :current-page="query.pageIndex"
                        :page-size="query.pageSize"
                        :total="pageTotal"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 患者信息弹出框 -->
        <el-dialog title="患者信息" :visible.sync="viewVisible" width="30%" :close-on-click-modal="false">
            <el-form ref="viewForm" :model="viewForm" label-width="90px">
                <el-form-item label="姓名:" prop="ptNm">
                    <el-input v-model="viewForm.ptNm" readonly></el-input>
                </el-form-item>
                <el-form-item label="性别:" prop="ptSexText">
                    <el-input v-model="viewForm.ptSexText" readonly></el-input>
                </el-form-item>
                <el-form-item label="年龄:" prop="ptAge">
                    <el-input v-model="viewForm.ptAge" readonly></el-input>
                </el-form-item>
                <el-form-item label="手机号:" prop="ptPhone">
                    <el-input v-model="viewForm.ptPhone" readonly></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="viewVisible = false">取 消</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import { monitorData, doView} from '../../../api/system/monitor/monitor';
    export default {
        name: 'monitors',
        data() {
            return {
                show: false,
                query: {
                    organNm: '',
                    bkOrganId: '',
                    pageIndex: 1,
                    pageSize: 10
                },
                tableData: [],
                multipleSelection: [],
                pageTotal: 0,
                idx: -1,
                id: -1,
                viewVisible: false,
                viewForm:{},
            };
        },
        created() {
            this.getData();
        },
        methods: {
            // 获取后台数据
            getData() {
                monitorData(this.query).then(res => {
                    if (res.success == true){
                        this.tableData = res.data;
                        this.pageTotal = res.total;
                    } else {
                        this.$message.error("查询失败！");
                        this.tableData = [];
                        this.pageTotal = 0;
                    }
                });
            },
            // 触发搜索按钮
            handleSearch() {
                this.$set(this.query, 'pageIndex', 1);
                this.getData();
            },
            // 触发重置按钮
            handleReset() {
                this.query.organNm = "";
                this.query.bkOrganId = "";
                this.getData();
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val);
                this.getData();
            },
            handleView(index, row){
                this.viewVisible = false;
                this.viewForm = {};
                let query = {
                    hospitalId: row.organId,
                    hospitalSystemId: row.bkOrganId,
                    systemType: row.systemType
                };
                doView(query).then(res =>{
                    if (res.success == true){
                        if (res.data == null){
                            this.$message.success("无患者训练！");
                        } else {
                            this.viewForm = res.data;
                            this.viewVisible = true;
                        }
                    } else {
                        this.viewVisible = false;
                        this.$message.error("无患者训练！");
                        this.getData();
                    }
                });
            }
        }
    };
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .table {
        width: 100%;
        font-size: 14px;
    }
    .red {
        color: #ff0000;
    }
    .mr10 {
        margin-right: 10px;
    }
    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
        /*border-radius 属性允许您为元素添加圆角边框！*/
        border-radius:6px;
        background-clip:padding-box;
        border-top-left-radius: 6px;
        border-top-right-radius: 6px;
        border-bottom-right-radius: 6px;
        border-bottom-left-radius: 6px;
    }
    /*头像上传*/
    .user-header{
        position: relative;
        display: inline-block;
    }
    .user-header-com{
        width: 100px;
        height: 100px;
        border-radius: 50%;
        display: inline-block;
    }
    .header-upload-btn{
        position: absolute;
        left: 0;
        top: 0;
        opacity: 0;
        /* 通过定位把input放在img标签上面，通过不透明度隐藏 */
    }
</style>
